// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from '../App'
import router from '../router'
import 'reset.css'
import 'vux/src/styles/reset.less'
import '@/less/tools.less'
import '@/less/main.less'
// import FastClick from 'fastclick'
import { LoadingPlugin } from 'vux'
import Velocity from 'velocity-animate'
import utils from '../utils'
import { wxShareApi } from '../service'
import { TransferDom } from 'vux'
Vue.directive('transfer-dom', TransferDom)
Vue.config.productionTip = false;
import VConsole from 'vconsole'

// new VConsole();

(function () {
  const channel = utils.queryString().channel;
  if ((!navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
    // window.location.href = `/show.html?channel=${channel}`
    window.location.href = `/camellia-sample/show.html?channel=${channel}`

  }
})()
document.getElementById('out_orient_layer').style.display = 'block'
Vue.prototype.$Velocity = Velocity
// FastClick.attach(document.body)
Vue.use(LoadingPlugin)


const windowSize = {
  width: document.documentElement.clientWidth,
  height: document.documentElement.clientHeight,
  ratio: window.devicePixelRatio,
  scale: document.documentElement.clientWidth / 375
},
  str = 'width=375, initial-scale=' + windowSize.scale + ', maximum-scale=' + windowSize.scale + ', minimum-scale=' + windowSize.scale + ', user-scalable=no';
document.getElementById("viewport").setAttribute("content", str);

window.alert = function (name) {
  const iframe = document.createElement('IFRAME');
  iframe.style.display = 'none';
  iframe.setAttribute('src', 'data:text/plain,');
  document.documentElement.appendChild(iframe);
  window.frames[0].window.alert(name);
  iframe.parentNode.removeChild(iframe);
}

// wxShare();

async function wxShare() {
  const appId = 'wxdb123cacad6e0afe';
  const requestUrl = window.location.href.split('#')[0];
  const callback = 'https://campaign.chanel.com.cn/wechat-api/refreshToken'
  const channel = utils.queryString().channel
    ? utils.queryString().channel
    : 'other';
  const config = {
    title: '香奈儿香水试用申领福利',
    link: `https://cocomademoisellesampling.chanel.com.cn/index.html?channel=${channel}`,
    desc: '馥郁新享法',
    imgUrl: 'https://cocomademoisellesampling.chanel.com.cn/static/logo.jpg'
  }
  const res = await wxShareApi({ appId, requestUrl });
  if (!utils.isWx())
    return;
  wx.config({
    debug: false,
    appId: appId,
    timestamp: parseInt(res.data.timestamp),
    nonceStr: res.data.noncestr,
    signature: res.data.signature,
    jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone']
  })
  wx.ready(() => {
    wx.onMenuShareAppMessage({
      title: config.title,
      desc: config.desc,
      link: config.link,
      imgUrl: config.imgUrl,
      success: function () { },
      cancel: function () { }
    })
    wx.onMenuShareTimeline({ title: config.title, link: config.link, imgUrl: config.imgUrl, success: function () { }, cancel: function () { } })
    wx.onMenuShareQQ({
      title: config.title,
      desc: config.desc,
      link: config.link,
      imgUrl: config.imgUrl,
      success: function () { },
      cancel: function () { }
    })
    wx.onMenuShareWeibo({
      title: config.title,
      desc: config.desc,
      link: config.link,
      imgUrl: config.imgUrl,
      success: function () { },
      cancel: function () { }
    })
    wx.onMenuShareQZone({
      title: config.title,
      desc: config.desc,
      link: config.link,
      imgUrl: config.imgUrl,
      success: function () { },
      cancel: function () { }
    })
  })
}

// 禁止分享
function onBridgeReady() {
  WeixinJSBridge.call('hideOptionMenu');
}
if (typeof WeixinJSBridge == "undefined") {
  if (document.addEventListener) {
    document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
  } else if (document.attachEvent) {
    document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
    document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
  }
} else {
  onBridgeReady();
}

if (/Android [4-9]/.test(navigator.appVersion)) {
  window.addEventListener("resize", function () {
    if (document.activeElement.tagName == "INPUT" || document.activeElement.tagName == "TEXTAREA") {
      window.setTimeout(function () {
        document.activeElement.scrollIntoViewIfNeeded();
      }, 0);
    }
  })
}

/* eslint-disable no-new */
new Vue({
  el: '#app', router, components: {
    App
  }, template: '<App/>'
})
